{include file="public/head"}
<body>
<div class="x-body">
    <div class="lotus-nav">

        <button class="layui-btn  layui-btn-sm"
                onclick="x_admin_show('添加用户','addUser.html',500)">
            <i class="layui-icon layui-icon-add-circle"></i>
        </button>

        <div class="layui-input-inline">
            <input id="search" name="search" class="layui-input lotus-input" placeholder="请输入登录名搜索" value="{$search}">
        </div>

        <button class="layui-btn layui-btn-sm" onclick="search()"><i class="layui-icon layui-icon-search"></i></button>
        <span class="x-right">共有数据:<i class="i_count">{$users->total()}</i>条 <button
                onclick="javascript:location.reload()" class="layui-btn-default "><i
                class="layui-icon layui-icon-refresh"></i></button></span>

    </div>


    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 40px;text-align: center">ID</th>
            <th>登录名</th>
            <th>真实姓名</th>
            <th style="width: 120px;text-align: center">所属角色</th>
            <th>注册邮箱</th>
            <th style="width: 80px;text-align:center">可用容量</th>
            <th style="width: 80px;text-align:center">已用容量</th>
            {if $type ==1}
            <th style="text-align:center">所属公司</th>
            {/if}
            <th style="width: 140px;text-align:center">最后登录时间</th>
            <th style="width: 110px;text-align:center">最后登录IP</th>
            <th style="text-align: center;width: 40px">状态</th>
            <th style="width: 90px;text-align:center">操作</th>
        </thead>
        <tbody>

        {volist name="$users" id="vo"}
        <tr>
            <td style="text-align: center">{$i}</td>
            <td>{$vo.username}</td>
            <td>{$vo.truename}</td>
            <td style="text-align: center">
                {if isset($auth_group[$vo['role_id']]['title'])}
                {$auth_group[$vo['role_id']]['title']}
                {/if}
            </td>
            <td>{$vo.email}</td>
            <td style="text-align: center">
                {if isset($companys[$vo['company_id']]['upload_capacity'])}
                {$companys[$vo['company_id']]['upload_capacity']}GB
                {else/}
                不限
                {/if}
            </td>
            <td style="text-align: center">{$companys[$vo['company_id']]['use_capacity']|default='不限'}</td>
            {if $type ==1}
            <th style="text-align:center">{$companys[$vo['company_id']]['name']|default='总公司'}</th>
            {/if}
            <td style="text-align: center">
                {if condition="empty($vo.last_login_time)"}
                此用户还未使用
                {else /}
                {$vo.last_login_time}
                {/if}
            </td>
            <td style="text-align: center">{$vo.last_login_ip}</td>
            <td style="text-align: center">
                {if $vo['status'] == 2}
                <b style="color: red">禁用</b>
                {else/}
                <b style="color: green">启用</b>
                {/if}
            </td>
            <td style="text-align: center">
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('编辑用户','editUser.html?id={$vo.id}',500)">编辑
                </button>
                <button onclick="delUser(this,{$vo.id})" class="layui-btn layui-btn-xs layui-btn-danger">删除</button>
            </td>
        </tr>
        {/volist}

        </tbody>
    </table>
    <div class="page">
        <div>
            {$users->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    function search() {
        var search = $("#search").val();
        location.href = "userlist.html?search=" + search;
    }

    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    function delUser(obj, id) {
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/user/deleteUser')}", {id: id}, function (data, textStatus, xhr) {
                /*optional stuff to do after success */
                console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
</script>
